package project06;
/**
 * Title: ArrayProject class for CSIS 235 Project 6
 * Description: CS 235 Project #6
 *              Arrays: using the clone method of arrays
 * @author Anthony Varghese
 * @email  your.n.here@my.uwrf.edu
 * @date   February 5th 2012
 */

public class ArrayProject {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// Set up an array - the old fashioned way
		int[] simple = new int[10];
			
		// cloning of arrays is allowed:
		int[] copy = simple.clone();
			
		System.out.print( " simple is " ); print( simple );
		System.out.print( "  copy == clone of simple is " ); print( copy );

		System.out.println("     According to .equals: simple and copy are " +
					(simple.equals( copy ) ? " the same." : "different.") );
		System.out.println("     According to Arrays.equals: simple and copy are " +
			(java.util.Arrays.equals( simple, copy ) ? " the same." : " different.") );
		System.out.println();
			
		/*
		 * Change an element in the simple array. If the copy array is also changed, 
		 * then we know that copy was merely pointing to simple.
		 * If the copy array is unchanged, then we know that the clone method call
		 * made a copy of the elements in simple. 
		 */
		simple[2] = 5;

		System.out.print( " simple is " ); print( simple );
		System.out.print( "  copy == clone of simple is " ); print( copy );

		System.out.println("     According to .equals: simple and copy are " +
					(simple.equals( copy ) ? " the same." : "different.") );
		System.out.println("     According to Arrays.equals: simple and copy are " +
			(java.util.Arrays.equals( simple, copy ) ? " the same." : " different.") );
		System.out.println();

			
		// We can also use the curly brace syntax to create
		// an array and set its values in one step:
		int[] easy   = {1, 2, 3, 4, 5, 6, 7, 8};

		copy = easy.clone();

		System.out.print( " easy is " ); print( easy );
		System.out.print( "  copy == clone of easy is " ); print( copy );
			
		System.out.println("     According to Arrays.equals: easy and copy are " +
			(java.util.Arrays.equals( easy, copy ) ? " the same." : " different.") );
		System.out.println();
	}

	private static void print(int[] x){
		System.out.println( java.util.Arrays.toString(x) );
	}
}